package com.hxzy.servlet;

import com.hxzy.bean.HandSet;
import com.hxzy.service.HandSetService;
import com.hxzy.service.impl.HandSetServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author nick
 */
@WebServlet("/index")
public class IndexServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        //查询所有的手机信息，调用业务逻辑层
        HandSetService service = new HandSetServiceImpl();
        List<HandSet> handSets = service.queryAll();

        //将集合添加到request作用域
        req.setAttribute("handSets", handSets);

        //页面转发
        req.getRequestDispatcher("/index.jsp").forward(req,resp);
    }
}
